/// Example of a simple line chart.
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';
import 'package:flutterdemo/library/sqflite/face_provider.dart';
import 'package:flutterdemo/models/distribution.dart';

class ChartPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SimpleLineChart();
  }
}

class _SimpleLineChart extends State<ChartPage> {
  List<charts.Series> seriesList;

  bool animate;

  @override
  void initState() {
    super.initState();
    _initData();
  }

  @override
  Widget build(BuildContext context) {
    return new charts.LineChart(seriesList, animate: animate);
  }

  _initData() async {
    List<Distribution> list = await FaceModelProvider().queryDistribution();
    seriesList = [
      new charts.Series<Distribution, int>(
        id: 'Sales',
        colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
        domainFn: (Distribution sales, _) => int.parse(sales.xAxis),
        measureFn: (Distribution sales, _) => sales.yAxis,
        data: list,
      )
    ];
  }
}
